
"""
@名称：练习
@作者：Fida1214
@日期：2025/4/9
"""

"""
第六题，虚拟宠物养成
"""

import random

class Pet:
    def __init__(self, name, species):
        self.name = name
        self.species = species
        self.hunger = 0
        self.happiness = 100

    def feed(self):
        self.hunger -= 20
        if self.hunger < 0:
            self.hunger = 0
        self.happiness += 10
        print(f"你喂了 {self.name}，它现在不那么饿了，开心值增加到 {self.happiness}。")

    def play(self):
        if self.hunger > 50:
            print(f"{self.name} 太饿了，不想玩。")
        else:
            self.happiness += 30
            if self.happiness > 100:
                self.happiness = 100
            self.hunger += 10
            print(f"你和 {self.name} 玩得很开心，它的开心值达到了 {self.happiness}，但有点饿了。")

    def time_pass(self):
        self.hunger += 10
        self.happiness -= 5
        if self.hunger > 100:
            print(f"{self.name} 饿得很难受！")
        if self.happiness < 0:
            print(f"{self.name} 很不开心！")

cat = Pet("喵喵", "猫")

for _ in range(5):
    cat.time_pass()
    action = random.choice(["feed", "play"])
    if action == "feed":
        cat.feed()
    else:
        cat.play()
